package app.web.visual.tags;

import app.common.dao.Leo_tag_typeBean;
import cn.lily.com.exception.YaconException;
import cn.lily.com.lang.BusinessDate;
import cn.lily.web.page.BusinessPage;
import cn.lily.web.widget.page.TPanel;
import cn.lily.web.widget.standard.TTree;
import cn.lily.web.widget.standard.menu.TPopupMenu;
/**
 * 标签类型树
 * @author JiaJ
 *
 */
public class TagTree extends BusinessPage { 

	 public void page_onLoad() throws YaconException {

		 TPanel tagPanel = Panel("tagPanel");
		 tagPanel.creatToolbar().setBarText("标签分类表编辑");

		 TTree tagTree = Tree("tagTree");
		 
		 tagTree.setISEdit(true);
		 
		 tagTree.setRootKey("0");
		 tagTree.setRootCaption("标签分类表");
		 tagTree.setParentKeyName("UP_ID");
		 tagTree.setFieldKeyName("TAG_TYP_ID");
		 tagTree.setFieldCaptionName("TAG_TYP_NAM");
		 tagTree.setFieldCountName("IT_COUNT");
		 
		 tagPanel.createPanelCell(tagTree);
		 
		 getPage().addElement(tagPanel,2);
		 
		 //Frame 部分 
		 getPage().addElement(tagTree.createFrame("tagTreeFrame","about:blank;"),10);
		 
	 }

	 public void refresh() throws YaconException {

		 String sql = "";

		 if ("0".equals(this.getViewTable().getAttributeValue("treeLevel"))) {
			 sql = "select o.TAG_TYP_ID,o.TAG_TYP_NAM , 0 as IT_COUNT "
					 + "from ${schema}.LEO_TAG_TYPE o ";
		 }

		 this.setDataTable(getDataSet().setCommonSQL(sql));

	 }

	 public void save() throws YaconException {

		 Leo_tag_typeBean tagBean = new Leo_tag_typeBean();
		 while (getViewTable().next()) {
			 tagBean.setViewRecord(getViewTable().getRecord());

			 if (getViewTable().getRecord().getRecordType() == 1) {
				 
				 this.dataExistCommon(tagBean, "TAG_TYP_NAM", "改名称已经存在！");
				 
				 tagBean.setTag_typ_id(this.getDBSequence().getBussSeq("leo_tag_id", 8));
				 tagBean.setCreate_oper(this.getOperator().getOperId());
				 tagBean.setCreate_time(BusinessDate.getTodaytime());
				 
				 tagBean.insert();
			 }

			 else if (getViewTable().getRecord().getRecordType() == 2) {
				 
				 this.dataExistCommon(tagBean, "TAG_TYP_NAM", "改名称已经存在！");
				 
				 tagBean.updateByWhere("where TAG_TYP_ID='"+getViewTable().getString("TAG_TYP_ID")+"'");
			 }

			 else if (getViewTable().getRecord().getRecordType() == 3) {
				 
				 this.dataRelaDelete("LEO_TAG_TYP_RELA", "TAG_TYP_ID");
				 
				 tagBean.deleteByWhere("where TAG_TYP_ID='"+getViewTable().getString("TAG_TYP_ID")+"'");
			 }

		 }
		 this.setSuccess("数据操作成功！");

	 }


}
